package com.changzhi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.changzhi.ldyl.model.PaymentOrder;
import com.changzhi.ldyl.model.UserLoginLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Alfred
 * @since 2019-11-27
 */
public interface PaymentOrderMapper extends BaseMapper<PaymentOrder> {

    @Select("SELECT sum(cli_price) from yl_payment_order where cli_buyer_id = #{userId} and order_status ='OTHER_SUCCESS'")
    BigDecimal getUserTotalPaymentAmount(@Param("userId") String userId);
    
    @Select("SELECT sum(diamonds_amount) from yl_payment_order where cli_buyer_id = #{userId} and order_status ='OTHER_SUCCESS'")
    Integer getTotalDiamond(@Param("userId") String userId);

    @Select("select   count(porder.order_no)  from yl_payment_order porder INNER JOIN yl_user_login_log as ulog on ulog.user_id = porder.cli_buyer_id " +
            "  where ulog.md5 = #{deviceId} and porder.order_status = 'OTHER_SUCCESS'  ")
    Long getTotalSuccessOrder(@Param("deviceId") String deviceId);


    PaymentOrder getFristOrderByDeviceId(@Param("log") UserLoginLog log);

    PaymentOrder getSuccessFirstOrdersByUserId(@Param("userId") String userId);

}


